//
//  ECMineSafeCheckPsVc.m
//  Edu_iOS2018
//
//  Created by apple on 2018/1/15.
//  Copyright © 2018年 yanyan. All rights reserved.
//

#define Textfield_height        960*0.1406         //封装输入框的高度

#import "ECMineSafeCheckPsVc.h"
#import "ECUITextField_Account.h"
#import "ECMineSafeChangeOrBindTelVc.h"

#import "ECRegularExpression.h"


@interface ECMineSafeCheckPsVc (){
    
    ECUITextField_Account *uitf_name;
    ECUButton *loginBtn;
}
@end

@implementation ECMineSafeCheckPsVc

-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"修改手机号";
    
    uitf_name = [[ECUITextField_Account alloc]initWithFrame:CGRectMake(kProportion_Width(60), kProportion_Width(60), kScreenWidth - kProportion_Width(MarginLeft_Textfield*2) , kProportion_Height(Textfield_height)) placeholder:@"原手机号(验证身份)" leftImage:[UIImage imageNamed:@"pwd_user"]];
    [self.view addSubview:uitf_name];
    uitf_name.textField.keyboardType = UIKeyboardTypePhonePad;
    
    // login btn
    loginBtn = [ECUButton buttonWithType:UIButtonTypeCustom];
    [loginBtn setBackgroundImage:[UIImage imageNamed:@"flatButton_colorNormal"] forState:UIControlStateNormal];
    loginBtn.frame = CGRectMake(kProportion_Width(60), CGRectGetMaxY(uitf_name.frame) + kProportion_Height(MarginHeight_textfield), kScreenWidth - kProportion_Width(60*2),(kScreenWidth - kProportion_Width(60*2))* 0.1406);
    [loginBtn addTarget:self action:@selector(action_Login) forControlEvents:UIControlEventTouchUpInside];
    [loginBtn setBackgroundImage:[UIImage imageNamed:@"flatButton_colorSelected"] forState:UIControlStateHighlighted];
    [loginBtn setTitle:@"下一步" forState:UIControlStateNormal];
    loginBtn.titleLabel.font = [UIFont systemFontOfSize:ceil(20)];
    [loginBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [loginBtn setTitleColor:[UIColor lightGrayColor] forState:UIControlStateHighlighted];
    [self.view addSubview:loginBtn];
}

-(void)action_Login{
    if ([ECRegularExpression isPhoneNumber:uitf_name.textField.text] == YES){
        [HWHttpTool requestWithMethod:@"POST"
                                  url:URL_POST_CheckMobile
                               params:@{@"mobile":uitf_name.textField.text}
                              headers:@{@"X-AUTH-TOKEN":[[UserInfoManager shareUser] token]}
                              success:^(id json) {
                                  if ([json[@"code"] intValue] == 200) {
                                      ECMineSafeChangeOrBindTelVc *vc = [[ECMineSafeChangeOrBindTelVc alloc]init];
                                      vc.vcType = vcTypeFromChangeTel;
                                      [self.navigationController pushViewController:vc animated:YES];
                                      uitf_name.textField.text = @"";
                                  }else{
                                      [MBProgressHUD showTipMessageInWindow:json[@"message"]];
                                  }
                              } failure:^(NSError *error) {
                                  
                              }];
    }else{
        [MBProgressHUD showTipMessageInWindow:@"请输入正确的手机号"];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
